.class public Lorg/microemu/app/util/MIDletTimer;
.super Ljava/util/Timer;
.source "MIDletTimer.java"


# static fields
.field private static midlets:Ljava/util/Map;


# instance fields
.field private midletContext:Lorg/microemu/MIDletContext;

.field private name:Ljava/lang/String;


# direct methods
.method static constructor <clinit>()V
    .locals 1

    .prologue
    .line 49
    new-instance v0, Ljava/util/WeakHashMap;

    invoke-direct {v0}, Ljava/util/WeakHashMap;-><init>()V

    sput-object v0, Lorg/microemu/app/util/MIDletTimer;->midlets:Ljava/util/Map;

    return-void
.end method

.method public constructor <init>()V
    .locals 4

    .prologue
    const/4 v3, 0x1

    .line 56
    invoke-direct {p0}, Ljava/util/Timer;-><init>()V

    .line 57
    new-instance v1, Ljava/lang/Throwable;

    invoke-direct {v1}, Ljava/lang/Throwable;-><init>()V

    invoke-virtual {v1}, Ljava/lang/Throwable;->getStackTrace()[Ljava/lang/StackTraceElement;

    move-result-object v0

    .line 58
    .local v0, ste:[Ljava/lang/StackTraceElement;
    new-instance v1, Ljava/lang/StringBuffer;

    invoke-direct {v1}, Ljava/lang/StringBuffer;-><init>()V

    aget-object v2, v0, v3

    invoke-virtual {v2}, Ljava/lang/StackTraceElement;->getClassName()Ljava/lang/String;

    move-result-object v2

    invoke-virtual {v1, v2}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v1

    const-string v2, "."

    invoke-virtual {v1, v2}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v1

    aget-object v2, v0, v3

    invoke-virtual {v2}, Ljava/lang/StackTraceElement;->getMethodName()Ljava/lang/String;

    move-result-object v2

    invoke-virtual {v1, v2}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v1

    iput-object v1, p0, Lorg/microemu/app/util/MIDletTimer;->name:Ljava/lang/String;

    .line 59
    return-void
.end method

.method public static contextDestroyed(Lorg/microemu/MIDletContext;)V
    .locals 2
    .parameter "midletContext"

    .prologue
    .line 135
    if-nez p0, :cond_1

    .line 143
    :cond_0
    :goto_0
    return-void

    .line 138
    :cond_1
    sget-object v1, Lorg/microemu/app/util/MIDletTimer;->midlets:Ljava/util/Map;

    invoke-interface {v1, p0}, Ljava/util/Map;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Ljava/util/Map;

    .line 139
    .local v0, timers:Ljava/util/Map;
    if-eqz v0, :cond_0

    .line 140
    invoke-static {v0}, Lorg/microemu/app/util/MIDletTimer;->terminateTimers(Ljava/util/Map;)V

    .line 141
    sget-object v1, Lorg/microemu/app/util/MIDletTimer;->midlets:Ljava/util/Map;

    invoke-interface {v1, p0}, Ljava/util/Map;->remove(Ljava/lang/Object;)Ljava/lang/Object;

    goto :goto_0
.end method

.method private static register(Lorg/microemu/app/util/MIDletTimer;)V
    .locals 3
    .parameter "timer"

    .prologue
    .line 101
    iget-object v1, p0, Lorg/microemu/app/util/MIDletTimer;->midletContext:Lorg/microemu/MIDletContext;

    if-nez v1, :cond_0

    .line 102
    invoke-static {}, Lorg/microemu/MIDletBridge;->getMIDletContext()Lorg/microemu/MIDletContext;

    move-result-object v1

    iput-object v1, p0, Lorg/microemu/app/util/MIDletTimer;->midletContext:Lorg/microemu/MIDletContext;

    .line 104
    :cond_0
    iget-object v1, p0, Lorg/microemu/app/util/MIDletTimer;->midletContext:Lorg/microemu/MIDletContext;

    if-nez v1, :cond_1

    .line 105
    const-string v1, "Creating Timer with no MIDlet context"

    new-instance v2, Ljava/lang/Throwable;

    invoke-direct {v2}, Ljava/lang/Throwable;-><init>()V

    invoke-static {v1, v2}, Lorg/microemu/log/Logger;->error(Ljava/lang/String;Ljava/lang/Throwable;)V

    .line 116
    :goto_0
    return-void

    .line 108
    :cond_1
    sget-object v1, Lorg/microemu/app/util/MIDletTimer;->midlets:Ljava/util/Map;

    iget-object v2, p0, Lorg/microemu/app/util/MIDletTimer;->midletContext:Lorg/microemu/MIDletContext;

    invoke-interface {v1, v2}, Ljava/util/Map;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Ljava/util/Map;

    .line 109
    .local v0, timers:Ljava/util/Map;
    if-nez v0, :cond_2

    .line 111
    new-instance v0, Ljava/util/HashMap;

    .end local v0           #timers:Ljava/util/Map;
    invoke-direct {v0}, Ljava/util/HashMap;-><init>()V

    .line 112
    .restart local v0       #timers:Ljava/util/Map;
    sget-object v1, Lorg/microemu/app/util/MIDletTimer;->midlets:Ljava/util/Map;

    iget-object v2, p0, Lorg/microemu/app/util/MIDletTimer;->midletContext:Lorg/microemu/MIDletContext;

    invoke-interface {v1, v2, v0}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    .line 115
    :cond_2
    iget-object v1, p0, Lorg/microemu/app/util/MIDletTimer;->midletContext:Lorg/microemu/MIDletContext;

    invoke-interface {v0, p0, v1}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    goto :goto_0
.end method

.method private terminate()V
    .locals 0

    .prologue
    .line 97
    invoke-super {p0}, Ljava/util/Timer;->cancel()V

    .line 98
    return-void
.end method

.method private static terminateTimers(Ljava/util/Map;)V
    .locals 6
    .parameter "timers"

    .prologue
    .line 146
    invoke-interface {p0}, Ljava/util/Map;->keySet()Ljava/util/Set;

    move-result-object v4

    invoke-interface {v4}, Ljava/util/Set;->iterator()Ljava/util/Iterator;

    move-result-object v1

    .local v1, iter:Ljava/util/Iterator;
    :cond_0
    :goto_0
    invoke-interface {v1}, Ljava/util/Iterator;->hasNext()Z

    move-result v4

    if-eqz v4, :cond_2

    .line 147
    invoke-interface {v1}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v2

    .line 148
    .local v2, o:Ljava/lang/Object;
    if-eqz v2, :cond_0

    .line 151
    instance-of v4, v2, Lorg/microemu/app/util/MIDletTimer;

    if-eqz v4, :cond_1

    .line 152
    move-object v0, v2

    check-cast v0, Lorg/microemu/app/util/MIDletTimer;

    move-object v3, v0

    .line 153
    .local v3, tm:Lorg/microemu/app/util/MIDletTimer;
    new-instance v4, Ljava/lang/StringBuffer;

    invoke-direct {v4}, Ljava/lang/StringBuffer;-><init>()V

    const-string v5, "MIDlet timer created from ["

    invoke-virtual {v4, v5}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v4

    iget-object v5, v3, Lorg/microemu/app/util/MIDletTimer;->name:Ljava/lang/String;

    invoke-virtual {v4, v5}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v4

    const-string v5, "] still running"

    invoke-virtual {v4, v5}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v4

    invoke-virtual {v4}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v4

    invoke-static {v4}, Lorg/microemu/log/Logger;->warn(Ljava/lang/String;)V

    .line 154
    invoke-direct {v3}, Lorg/microemu/app/util/MIDletTimer;->terminate()V

    goto :goto_0

    .line 156
    .end local v3           #tm:Lorg/microemu/app/util/MIDletTimer;
    :cond_1
    new-instance v4, Ljava/lang/StringBuffer;

    invoke-direct {v4}, Ljava/lang/StringBuffer;-><init>()V

    const-string v5, "unrecognized Object ["

    invoke-virtual {v4, v5}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v4

    invoke-virtual {v2}, Ljava/lang/Object;->getClass()Ljava/lang/Class;

    move-result-object v5

    invoke-virtual {v5}, Ljava/lang/Class;->getName()Ljava/lang/String;

    move-result-object v5

    invoke-virtual {v4, v5}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v4

    const-string v5, "]"

    invoke-virtual {v4, v5}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v4

    invoke-virtual {v4}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v4

    invoke-static {v4}, Lorg/microemu/log/Logger;->debug(Ljava/lang/String;)V

    goto :goto_0

    .line 160
    .end local v2           #o:Ljava/lang/Object;
    :cond_2
    return-void
.end method

.method private static unregister(Lorg/microemu/app/util/MIDletTimer;)V
    .locals 3
    .parameter "timer"

    .prologue
    .line 119
    iget-object v1, p0, Lorg/microemu/app/util/MIDletTimer;->midletContext:Lorg/microemu/MIDletContext;

    if-nez v1, :cond_1

    .line 129
    :cond_0
    :goto_0
    return-void

    .line 123
    :cond_1
    sget-object v1, Lorg/microemu/app/util/MIDletTimer;->midlets:Ljava/util/Map;

    iget-object v2, p0, Lorg/microemu/app/util/MIDletTimer;->midletContext:Lorg/microemu/MIDletContext;

    invoke-interface {v1, v2}, Ljava/util/Map;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Ljava/util/Map;

    .line 124
    .local v0, timers:Ljava/util/Map;
    if-eqz v0, :cond_0

    .line 128
    invoke-interface {v0, p0}, Ljava/util/Map;->remove(Ljava/lang/Object;)Ljava/lang/Object;

    goto :goto_0
.end method


# virtual methods
.method public cancel()V
    .locals 0

    .prologue
    .line 92
    invoke-static {p0}, Lorg/microemu/app/util/MIDletTimer;->unregister(Lorg/microemu/app/util/MIDletTimer;)V

    .line 93
    invoke-super {p0}, Ljava/util/Timer;->cancel()V

    .line 94
    return-void
.end method

.method public schedule(Ljava/util/TimerTask;J)V
    .locals 0
    .parameter "task"
    .parameter "delay"

    .prologue
    .line 72
    invoke-static {p0}, Lorg/microemu/app/util/MIDletTimer;->register(Lorg/microemu/app/util/MIDletTimer;)V

    .line 73
    invoke-super {p0, p1, p2, p3}, Ljava/util/Timer;->schedule(Ljava/util/TimerTask;J)V

    .line 74
    return-void
.end method

.method public schedule(Ljava/util/TimerTask;JJ)V
    .locals 0
    .parameter "task"
    .parameter "delay"
    .parameter "period"

    .prologue
    .line 77
    invoke-static {p0}, Lorg/microemu/app/util/MIDletTimer;->register(Lorg/microemu/app/util/MIDletTimer;)V

    .line 78
    invoke-super/range {p0 .. p5}, Ljava/util/Timer;->schedule(Ljava/util/TimerTask;JJ)V

    .line 79
    return-void
.end method

.method public schedule(Ljava/util/TimerTask;Ljava/util/Date;)V
    .locals 0
    .parameter "task"
    .parameter "time"

    .prologue
    .line 62
    invoke-static {p0}, Lorg/microemu/app/util/MIDletTimer;->register(Lorg/microemu/app/util/MIDletTimer;)V

    .line 63
    invoke-super {p0, p1, p2}, Ljava/util/Timer;->schedule(Ljava/util/TimerTask;Ljava/util/Date;)V

    .line 64
    return-void
.end method

.method public schedule(Ljava/util/TimerTask;Ljava/util/Date;J)V
    .locals 0
    .parameter "task"
    .parameter "firstTime"
    .parameter "period"

    .prologue
    .line 67
    invoke-static {p0}, Lorg/microemu/app/util/MIDletTimer;->register(Lorg/microemu/app/util/MIDletTimer;)V

    .line 68
    invoke-super {p0, p1, p2, p3, p4}, Ljava/util/Timer;->schedule(Ljava/util/TimerTask;Ljava/util/Date;J)V

    .line 69
    return-void
.end method

.method public scheduleAtFixedRate(Ljava/util/TimerTask;JJ)V
    .locals 0
    .parameter "task"
    .parameter "delay"
    .parameter "period"

    .prologue
    .line 87
    invoke-static {p0}, Lorg/microemu/app/util/MIDletTimer;->register(Lorg/microemu/app/util/MIDletTimer;)V

    .line 88
    invoke-super/range {p0 .. p5}, Ljava/util/Timer;->scheduleAtFixedRate(Ljava/util/TimerTask;JJ)V

    .line 89
    return-void
.end method

.method public scheduleAtFixedRate(Ljava/util/TimerTask;Ljava/util/Date;J)V
    .locals 0
    .parameter "task"
    .parameter "firstTime"
    .parameter "period"

    .prologue
    .line 82
    invoke-static {p0}, Lorg/microemu/app/util/MIDletTimer;->register(Lorg/microemu/app/util/MIDletTimer;)V

    .line 83
    invoke-super {p0, p1, p2, p3, p4}, Ljava/util/Timer;->schedule(Ljava/util/TimerTask;Ljava/util/Date;J)V

    .line 84
    return-void
.end method
